<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>ERP管理系统</title>
    <th:block th:include="include::header"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">


            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>用户名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    将会成为您唯一的登入用户名
                </div>
            </div>


            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="password" required="" lay-verify="pass"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    6到16个字符
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="roleId" class="layui-form-label">
                    <span class="x-red">*</span>角色
                </label>
                <div class="layui-input-inline">
                <select type="" id="roleId" name="roleId" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    <option ></option>
                    <th:block th:each="item:${roles}">
                        <option th:if="${item.roleName!='超级管理员'}" th:value="${item.roleId}">[[${item.roleName}]]</option>
                    </th:block>
                </select>
                </div>
            </div>


            <div class="layui-form-item">
                <label for="userLockout" class="layui-form-label">
                    <span class="x-red">*</span>状态
                </label>
                <div class="layui-input-inline">
                    <select type="" id="userLockout" name="userLockout" required="" lay-verify="required"
                            autocomplete="off" class="layui-input"><br>
                        <option ></option>
                        <option value="1" >有效用户</option>
                        <option value="0" >锁定</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script >layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        $(".select").css("width","190px");
        //自定义验证规则
        form.verify({
            nikename: function(value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            },
            Ndouble:[
                /^[1-9]\d*$/
                ,'年龄输入有误，请重新输入'
            ]
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                $.post("/user/add",data.field,function(date){
                    if(date.success){
                        layer.alert(date.msg, {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    }else{
                        layer.alert(date.msg, {icon:5});
                        return;
                    }
                });
                return false;
            });

    });</script>
</body>

</html>
